<style lang="less">
  #div_truck_load_order_close_dialog {
  }
</style>

<template>
  <div id="div_truck_load_order_close_dialog">
    <el-dialog :visible.sync="isShow" width="30%" title="关闭订单">
      <el-form ref="tloForm" :model="tloForm" label-width="130px">
        <el-form-item label="关闭描述" prop="closedOrderDescription"
                      :rules="{ required: true, message: '请输入关闭描述', trigger: 'change' }">
          <el-input class="f-w70" type="textarea"
                    v-model="tloForm.closedOrderDescription"></el-input>
        </el-form-item>
        <el-form-item label="是否需要退信息费">
          <el-checkbox v-model="tloForm.isRefundInfoFee"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="f-fr f-ml10" @click="changeStatus">确 认</el-button>
          <el-button class="f-fr" @click="isShow=!isShow">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  changeStatus
} from '../../api/truck-load/TruckLoadOrder.js';

export default {
  name: 'TruckLoadOrderCloseDialog',
  props: {
    truckLoadOrderCloseModel: {
      type: String,
      required: Boolean
    }
  },
  watch: {
    truckLoadOrderCloseModel (val) {
      let model = JSON.parse(val);
      this.tloForm.id = model.id;
      this.tloForm.closedOrderDescription = null;
      this.tloForm.isRefundInfoFee = null;
      this.isShow = model.isShow;
      console.log(model);
    }
  },
  data () {
    return {
      isShow: false,
      tloForm: {
        id: null,
        closedOrderDescription: null,
        isRefundInfoFee: null
      }
    };
  },
  methods: {
    changeStatus () {
      this.$refs['tloForm'].validate(tloFormValid => {
        if (tloFormValid) {
          this.tloForm.isRefundInfoFee = (this.tloForm.isRefundInfoFee != null && this.tloForm.isRefundInfoFee === true) ? 111002001 : 111002002;
          changeStatus(this.tloForm.id, 101015007, this.tloForm.closedOrderDescription, this.tloForm.isRefundInfoFee).then(res => {
            if (res.status === 200) {
              this.$message.success('订单关闭成功');
              this.isShow = false;
              this.$emit('isRefresh', true);
            }
          });
        }
      });
    }
  },
  mounted () {}
};
</script>
